package br.com.fabrica.aid.aid_fabrica.view;

import java.util.Iterator;
import java.util.List;
import javax.inject.Inject;
import br.com.fabrica.aid.aid_fabrica.business.CoordenadorBC;
import br.com.fabrica.aid.aid_fabrica.domain.Coordenador;
import br.gov.frameworkdemoiselle.annotation.NextView;
import br.gov.frameworkdemoiselle.annotation.PreviousView;
import br.gov.frameworkdemoiselle.stereotype.ViewController;
import br.gov.frameworkdemoiselle.template.AbstractListPageBean;
import br.gov.frameworkdemoiselle.transaction.Transactional;

@ViewController
@NextView("./coordenador_edit.xhtml")
@PreviousView("./coordenador_list.xhtml")
public class CoordenadorListMB extends AbstractListPageBean<Coordenador, Long> {

	private static final long serialVersionUID = 1L;

	@Inject
	private CoordenadorBC co;

	@Override
	protected List<Coordenador> handleResultList() {
		return this.co.findAll();
	}

	@Transactional
	public String deleteSelection() {
		boolean delete;
		for (Iterator<Long> iter = getSelection().keySet().iterator(); iter.hasNext();) {
			Long idcoordenador = iter.next();
			delete = getSelection().get(idcoordenador);

			if (delete) {
				co.delete(idcoordenador);
				iter.remove();
			}
		}
		return getPreviousView();
	}

}